<template>


  <div>

    <!--  查询-->
    <el-card>

      <el-form inline label-width="90px" size="mini" class="demo-form-inline">

        <el-form-item label="产品">
          <el-select v-model="queryParam.productId" placeholder="请选择" clearable filterable >
            <el-option
              v-for="item in productIdList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称">
          <el-input placeholder="请输入产品名称" v-model.trim="queryParam.productName" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="问题描述">
          <el-input placeholder="请输入问题描述" v-model.trim="queryParam.problem" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="出现频率">
          <el-select v-model="queryParam.frequency" placeholder="请选择" clearable  >
            <el-option key="1" label="一星" :value="1"/>
            <el-option key="2" label="二星" :value="2"/>
            <el-option key="3" label="三星" :value="3"/>
            <el-option key="4" label="四星" :value="4"/>
            <el-option key="5" label="五星" :value="5"/>
          </el-select>
        </el-form-item>
        <el-form-item label="问题状态">
          <el-select v-model="queryParam.status" placeholder="请选择" clearable  >
            <el-option key="1" label="开放中" :value="1"/>
            <el-option key="2" label="已关闭" :value="2"/>
            <el-option key="3" label="已过时" :value="3"/>
          </el-select>
        </el-form-item>



        <el-form-item>
          <el-button type="success" size="mini" @click="getListPage">查询</el-button>
          <el-button type="info" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="warning" size="mini" @click="openSaveBefore">新增</el-button>
        </el-form-item>

      </el-form>

    </el-card>





    <!--列表-->
    <el-card style="margin-top: 10px">

      <el-table
          :data="tableData"
          max-height="650px"
          height="650px"
          style="width: 100%">


        <el-table-column prop="productName" label="产品名称" width="150"/>
        <el-table-column prop="problem" label="问题描述"/>

        <el-table-column label="状态" width="80">
          <template slot-scope="scope">
            <el-tag size="mini" v-if="scope.row.status === 1">开放中</el-tag>
            <el-tag size="mini" type="info" v-else-if="scope.row.status === 2">已关闭</el-tag>
            <el-tag size="mini" type="warning" v-else-if="scope.row.status === 3">已过时</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="评分" width="50">
          <template slot-scope="scope">
            <el-tag size="mini" type="success" >{{scope.row.fraction}}</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="频率" width="150">
          <template slot-scope="scope">
            <el-rate disabled v-model="scope.row.frequency" />
          </template>
        </el-table-column>


        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="openViewBefore(scope.row)" type="text" size="small"><i class="el-icon-view"></i>查看</el-button>
            <el-button @click="openUpdBefore(scope.row)" type="text" size="small"><i class="el-icon-edit"></i>编辑</el-button>
            <el-button @click="delTips(scope.row)" type="text" size="small"><i class="el-icon-delete"></i>删除</el-button>
          </template>
        </el-table-column>

      </el-table>


      <!--分页部分-->
      <el-pagination
          style="width:33%; margin-right:10px; margin-top:10px;"
          background
          layout="total, prev, pager, next, jumper"
          @current-change="pageCurrentChange"
          :page-size="pageConfig.size"
          :current-page="pageConfig.current"
          :pager-count="5"
          :total="pageConfig.total">
      </el-pagination>

    </el-card>

    <OpsProductQuestionSaveUpd  ref="OpsProductQuestionSaveUpdRef" @getListPage="getListPage"/>
    <OpsProductQuestionDetailed ref="OpsProductQuestionDetailedRef"/>

  </div>

</template>


<script>

import http from '@/utils/http'
import OpsProductQuestionSaveUpd  from './OpsProductQuestionSaveUpd.vue'
import OpsProductQuestionDetailed from './OpsProductQuestionDetailed.vue'


export default {
  name: "OpsProductQuestionList",
  components: {
    OpsProductQuestionSaveUpd,
    OpsProductQuestionDetailed,
  },
  data() {
    return {
      // 查询参数
      queryParam: {
        productId: null,
        productName: null,
        problem: null,
        frequency: null,
        status: null,
      },
      // 分页参数
      pageConfig: {
        // 每页记录数
        size: 20,
        // 当前页码
        current: 1,
        // 总记录数
        total: 0,
      },
      // 表格数据
      tableData: [],
      // 全部产品
      productIdList: [],
    }
  },
  methods: {
    /**
     * 打开保存的弹框
     */
    openSaveBefore() {
      this.$refs.OpsProductQuestionSaveUpdRef.init('save', null)
    },
    /**
     * 查看之前触发
     * @param obj 这一行数据
     */
    openViewBefore(obj){
      this.$refs.OpsProductQuestionDetailedRef.init(obj)
    },
    /**
     * 打开修改之前的的弹出框
     * @param obj 修改的值
     */
    openUpdBefore(obj) {
      this.$refs.OpsProductQuestionSaveUpdRef.init('upd', obj)
    },
    /**
     * 删除之前的提示框
     * @param obj 要删除的数据
     */
    delTips(obj) {
      this.$confirm('是否执行删除, 删除后无法恢复，是否继续?', '提示', {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消删除',
        type: 'warning'
      }).then(() => {
        // 确定删除
        this.delOpsProductQuestion(obj)

      }).catch(() => {
        // 取消删除
      });
    },
    /**
     * 删除
     * @param obj 要删除的数据
     */
    delOpsProductQuestion(obj) {
      http.post("opsProductQuestion/delOpsProductQuestion", {
        id: obj.id,
      }).then(response => {
        let res = response.data;
        this.getListPage()
        this.$message.success("删除成功");

      }).catch(error => {
        this.$message.error (error.message)
      })
    },
    /**
     * 分支分页查询列表
     */
    getListPage() {
      this.queryParam.current = this.pageConfig.current
      this.queryParam.size = this.pageConfig.size
      http.post("/opsProductQuestion/getListPage", this.queryParam).then(response => {
        let res = response.data;
        // 分页数据
        let data = res.data;
        this.pageConfig.total = data.total;
        this.pageConfig.current = data.current;
        this.pageConfig.size = data.size;
        // 表格数据
        this.tableData = data.records

      }).catch(error => {
        this.$message.error (error.message);
      })
    },
    /**
     * 分页被改变的时候
     * @param value 当前页
     */
    pageCurrentChange(value) {
      this.pageConfig.current = value
      this.getListPage()
    },
     /**
     * 重置查询条件
     */
    resetQuery() {
      this.queryParam = {
        productId: null,
        productName: null,
        problem: null,
        frequency: null,
        status: null,
      }
    },
     /**
     * 分页前重置分页参数
     */
    getPageListBefore() {
      this.pageConfig.current = 1
      this.getListPage()
    },
    /**
     * 分页查询产品-全部
     */
    getProductListPage(){
      let queryParam = {
        current:1,
        size:9999,
      }
      http.post("/opsProduct/getListPage", queryParam).then(response => {
        let res = response.data;
        // 分页数据
        let data = res.data;
        // 表格数据
        this.productIdList = data.records

      }).catch(error => {
        this.$message.error (error.message);
      })
    },
  },
  // 进入马上执行
  mounted() {
    this.getListPage()
    // 全部的产品
    this.getProductListPage()
    this.$store.commit ('navigationListChange', [
      {name: '产品常用问题', url: '/toOpsProductQuestionList', query: {}},
    ])
  },
}
</script>

<style scoped>

</style>

